package cn.edu.stu.syllabus.widgets;

import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

/**
 * Created by daidaijie on 2017/4/24.
 */

public abstract class DrawableRightClickListener implements View.OnTouchListener {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        final int DRAWABLE_RIGHT = 2;

        TextView textView = (TextView) v;
        if (event.getAction() == MotionEvent.ACTION_UP) {
            if (event.getRawX() >= (textView.getRight() - textView.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
                onRightDrawableClick();
                return true;
            }
            return false;
        }
        return false;
    }

    public abstract void onRightDrawableClick();
}
